package com.collect.tanzania.zhiAdater.zhiDs;

import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.collect.tanzania.R;
import com.collect.tanzania.zhiBean.zhiReceive.ZHIRDsEntity;
import com.collect.tanzania.zhiScene.zhiDs.zhiFollow.ZHIDsActionType;
import com.collect.tanzania.zhiScene.zhiWidget.zhiStepView.ZHINextStepView;

public class ZHIDsListAdjuster extends BaseQuickAdapter<ZHIRDsEntity, BaseViewHolder> {

    public ZHIDsListAdjuster() {
        super(R.layout.item_ds_list, null);
    }

    private OnDsItemClickListener mOnDsItemClickListener;

    @Override
    protected void convert(BaseViewHolder helper, final ZHIRDsEntity zhirDsEntity) {
        helper.setText(R.id.tvName, zhirDsEntity.getFullName());
        helper.setText(R.id.tvMobile, zhirDsEntity.getMobileFormat());
        helper.setText(R.id.tvRelationship, zhirDsEntity.getContactRelation());
        helper.setText(R.id.tvRelationName, zhirDsEntity.getContactFullName());
        helper.setText(R.id.tvRelationMobile, zhirDsEntity.getContactMobile());

        ImageView ivDsMobileCall = helper.getView(R.id.ivDsMobileCall);
        ivDsMobileCall.setOnClickListener(view -> {
            if (mOnDsItemClickListener != null) {
                mOnDsItemClickListener.OnItemClick(zhirDsEntity, ZHIDsActionType.CALL_PHONE_SELF);
            }
        });

        ImageView ivDsMobileCopy = helper.getView(R.id.ivDsMobileCopy);
        ivDsMobileCopy.setOnClickListener(view -> {
            if (mOnDsItemClickListener != null) {
                mOnDsItemClickListener.OnItemClick(zhirDsEntity, ZHIDsActionType.COPY_MOBILE);
            }
        });

        ImageView ivCallPhone = helper.getView(R.id.ivDsCallPhone);
        ivCallPhone.setOnClickListener(view -> {
            if (mOnDsItemClickListener != null) {
                mOnDsItemClickListener.OnItemClick(zhirDsEntity, ZHIDsActionType.CALL_PHONE);
            }
        });

        ImageView ivCallWhatsapp = helper.getView(R.id.ivDsCallWhatsapp);
        ivCallWhatsapp.setOnClickListener(view -> {
            if (mOnDsItemClickListener != null) {
                mOnDsItemClickListener.OnItemClick(zhirDsEntity, ZHIDsActionType.CALL_WHATSAPP);
            }
        });

        ZHINextStepView btnNameMatch = helper.getView(R.id.btnNameMatch);
        btnNameMatch.setOnMenuItemDidChangedListener(item -> {
            if (mOnDsItemClickListener != null) {
                mOnDsItemClickListener.OnItemClick(zhirDsEntity, ZHIDsActionType.RESULT_NAME_MATCH);
            }
        });

        ZHINextStepView btnNameNotMatch = helper.getView(R.id.btnNameNotMatch);
        btnNameNotMatch.setOnMenuItemDidChangedListener(item -> {
            if (mOnDsItemClickListener != null) {
                mOnDsItemClickListener.OnItemClick(zhirDsEntity, ZHIDsActionType.RESULT_NAME_NOT_MATCH);
            }
        });

        ZHINextStepView btnNameAbnormalNumber = helper.getView(R.id.btnNameAbnormalNumber);
        btnNameAbnormalNumber.setOnMenuItemDidChangedListener(item -> {
            if (mOnDsItemClickListener != null) {
                mOnDsItemClickListener.OnItemClick(zhirDsEntity, ZHIDsActionType.RESULT_ABNORMAL_NUMBER_SELF);
            }
        });

        ZHINextStepView btnNotCallSuccess = helper.getView(R.id.btnNotCallSuccess);
        btnNotCallSuccess.setOnMenuItemDidChangedListener(item -> {
            if (mOnDsItemClickListener != null) {
                mOnDsItemClickListener.OnItemClick(zhirDsEntity, ZHIDsActionType.RESULT_NO_ANSWER);
            }
        });

        ZHINextStepView btnNeedAmount = helper.getView(R.id.btnNeedAmount);
        btnNeedAmount.setOnMenuItemDidChangedListener(item -> {
            if (mOnDsItemClickListener != null) {
                mOnDsItemClickListener.OnItemClick(zhirDsEntity, ZHIDsActionType.RESULT_KNOW_USER);
            }
        });

        ZHINextStepView btnNotNeedAmount = helper.getView(R.id.btnNotNeedAmount);
        btnNotNeedAmount.setOnMenuItemDidChangedListener(item -> {
            if (mOnDsItemClickListener != null) {
                mOnDsItemClickListener.OnItemClick(zhirDsEntity, ZHIDsActionType.RESULT_NOT_KNOW_USER);
            }
        });

        ZHINextStepView btnActionAbnormalNumber = helper.getView(R.id.btnActionAbnormalNumber);
        btnActionAbnormalNumber.setOnMenuItemDidChangedListener(item -> {
            if (mOnDsItemClickListener != null) {
                mOnDsItemClickListener.OnItemClick(zhirDsEntity, ZHIDsActionType.RESULT_ABNORMAL_NUMBER_CONTACT);
            }
        });

        RelativeLayout rlRelationshipBg = helper.getView(R.id.rlRelationshipBg);
        LinearLayout llResultOptionBg = helper.getView(R.id.llResultOptionBg);
        LinearLayout llNameOptionBg = helper.getView(R.id.llNameOptionBg);
        if (zhirDsEntity.isNameMatchFlag()) {
            llNameOptionBg.setVisibility(View.GONE);
            llResultOptionBg.setVisibility(View.VISIBLE);
            rlRelationshipBg.setVisibility(View.VISIBLE);
            helper.setText(R.id.tvMobile, zhirDsEntity.getMobileFormat());
            ivDsMobileCopy.setVisibility(View.GONE);
            ivDsMobileCall.setVisibility(View.GONE);

        } else {
            llNameOptionBg.setVisibility(View.VISIBLE);
            llResultOptionBg.setVisibility(View.GONE);
            rlRelationshipBg.setVisibility(View.GONE);
            helper.setText(R.id.tvMobile, zhirDsEntity.getMobileFormat());
            ivDsMobileCall.setVisibility(View.VISIBLE);
            ivDsMobileCopy.setVisibility(View.VISIBLE);
        }
    }

    public void setOnDsItemClickListener(OnDsItemClickListener onOrderItemClickListener) {
        this.mOnDsItemClickListener = onOrderItemClickListener;
    }

    public interface OnDsItemClickListener {
        void OnItemClick(ZHIRDsEntity zhirDsEntity, String actionType);
    }
}